#include <iostream>
using namespace std;
/*  单例类的构造函数为私有
    提供一个自身的静态私有成员变量
    提供一个公有的静态工厂方法
*/
class Singleton{
public:
    static Singleton* Instance(){
        // 懒汉式碰上多线程，不安全
        if(!_instance){
            _instance = new Singleton();
        }
        return _instance;
    }
private:
    Singleton(){cout << "Sigleton..." << endl;}
    static Singleton* _instance;
};

Singleton* Singleton::_instance = nullptr;

int main(){
    Singleton * singleton1 = Singleton::Instance();
    cout << singleton1 << endl;
    Singleton * singleton2 = Singleton::Instance();
    cout << singleton2 << endl;
    delete Singleton::Instance();
    return 0;
}